package com.coco.group.controller;

import com.coco.common.annotation.IngoreResponseAdvice;
import com.coco.group.pojo.TbGroupOrder;
import com.coco.group.service.GroupOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author minicoco
 * @version 1.0
 * @date 2021/7/30 19:35
 * 拼团订单
 */
@RestController
@RequestMapping("/group/order")
public class GroupOrderController {

    @Autowired
    private GroupOrderService groupOrderService;

    /**
     * 查询用户订单
     * @param userId
     * @param status
     * @return
     */
    @GetMapping("/findByUserIdAndStatus")
    public TbGroupOrder findByUserIdAndStatus(@RequestParam("userId")Long userId,@RequestParam("status")String status){
        return groupOrderService.findByUserIdAndStatus(userId,status);
    }

    /**
     * 查询单条
     * @param id
     * @return
     */
    @GetMapping("/findByOrderId/{id}")
    @IngoreResponseAdvice
    public TbGroupOrder findByOrderId(@PathVariable("id") String id){
        return groupOrderService.findByOrderId(id);
    }

    /**
     * 修改订单信息
     * @param groupOrder
     */
    @PutMapping("/updateOrder")
    @IngoreResponseAdvice
    public void updateOrder(@RequestBody TbGroupOrder groupOrder){
        groupOrderService.updateOrder(groupOrder);
    }

    /**
     * 修改订单状态
     * @param tradeNo
     * @param status
     */
    @GetMapping("/updateOrderStatus")
    @IngoreResponseAdvice
    public void updateOrderStatus(@RequestParam("orderId") String tradeNo,@RequestParam("status") Integer status){
        groupOrderService.updateOrderStatus(tradeNo,status);
    }
}
